<template>
	<view>
		<textarea placeholder="请输入您需要反馈的内容"  v-model="feedback.feedbackContent"  ></textarea>
		<button @click="uploadImg" type="primary" >上传图片</button>
		<view  @click="uploadImg"  >
			<image :src="feedback.pic" v-model="feedback.pic" ></image>
		</view>
		<view class="uni-form-item uni-column">
					<view class="title">反馈类型</view>
					<radio-group class="uni-list" @change="radioChange">
							<label class="uni-list-cell uni-list-cell-pd" v-for="(item,index) in radioItems" :key="index">
									<radio :id="item.name" :value="item.name" :checked="item.checked"></radio>
									<label class="label-2-text" :for="item.name">
										<text>{{item.value}}</text>
									</label>
							</label>
					</radio-group>
		</view>
		<button size="mini" type="primary"  @click="save"  plain>提交</button>
		
	</view>
</template>

<script>
	export default{
		data(){
			return{
				feedback:{
					feedbackContent:'',
					pic:'',
					feedbackTypeId:1,
					userId:'2'
				},
				 radioItems: [{
				                    name: '1',
				                    value: 'APP使用疑问',
									 checked: 'true'
				                },
				                {
				                    name: '2',
				                    value: '投诉举报',
				                },
								{
								    name: '3',
								    value: 'Bug反馈'
								},
								{
								    name: '4',
								    value: '活动咨询'
								},
				            ]
				
			}
		},
		onLoad() {
			
		},
		methods:{
			save(){
				console.log(this.feedback)
				uni.request({
					url:`http://localhost:7000/customer/userFeedback`,
					data:this.feedback,
					method:'POST',
					success:res=>{
						this.feedback.feedbackContent=''
						this.feedback.pic=''
						uni.showToast({
							title: '反馈成功',
							duration: 2000
						});
					}
				})
		
			},
			radioChange(e){
				//console.log('e',e.detail.value)
				this.feedback.feedbackTypeId=e.detail.value
			},
			uploadImg(){
				uni.chooseImage({
					count:1,
					 sizeType: ['original'], //可以指定是原图还是压缩图，默认二者都有
					 sourceType: ['album'], //从相册选择
					 success:res=>{
						this.feedback.pic=res.tempFilePaths[0]
						 //上传给后台
						 uni.uploadFile({
							 url:`http://localhost:7000/customer/uploadFile`,
							 filePath:res.tempFilePaths[0],
							 name:'file',
							 success:(uploadFileRes)=>{
								 this.feedback.pic=uploadFileRes.data
							 }
						 })
					 }
				})
			}
		}
		
	}
</script>

<style>
</style>
